package org.example.maven.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.maven.api.client.ActionInventoryClient;
import org.example.maven.entity.ActionTicket;
import org.example.maven.mapper.ActionTicketMapper;
import org.example.maven.service.ActionTicketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import static org.example.maven.common.StaticVariable.Action_Ticket_Inventory;

@Service
public class ActionTicketServiceImpl extends ServiceImpl<ActionTicketMapper, ActionTicket> implements ActionTicketService {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    @Autowired
    private ActionInventoryClient actionInventoryClient;
    @Override
    public void saveActionTicket(ActionTicket actionTicket) {
        baseMapper.insertOrUpdate(actionTicket);
        actionInventoryClient.addActionTicket(actionTicket);
        //将活动的可销售票数存到redis中
        stringRedisTemplate.opsForValue().set(Action_Ticket_Inventory+actionTicket.getId(),actionTicket.getAcTicketNumber().toString());
    }
}
